/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.coupon.service.CouponService
   Module Description   :

   Date Created      : 2009/11/24
   Original Author   : jeff.ma
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.coupon.service;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.ec.coupon.entity.Coupon;
import com.yaodian100.ec.coupon.entity.CouponItem;
import com.yaodian100.ec.member.entity.Member;
import com.yaodian100.ec.order.entity.OrderProduct;
import com.yaodian100.ec.order.entity.Orders;
import com.yaodian100.ec.shopping.entity.CartOrderProduct;

/**
 * @author jeff.ma
 * 
 */
public interface CouponService extends DomainService<Coupon> {

	public final static String ERROR_COUPON_ISUSED = "error.coupon.isused";
	public final static String ERROR_COUPON_ISEXPIRED = "error.coupon.isexpired";
	public final static String ERROR_COUPON_INACTIVE = "error.coupon.inactive";
	public final static String ERROR_COUPON_NOOWNER = "error.coupon.noowner";

	/**
	 * 已 file 建立 coupon item, 並回傳建立的 item 數 若 coupon status 為已使用, throw exception
	 * 
	 * @param coupon
	 * @param file format 應為 csv, [memberId]<Enter>; 若為 null 表示為預建未 assign member coupon
	 * @return
	 * @throws CoreException error.coupon.isused
	 */
	public Coupon generate(Coupon coupon, File file, String isSendMail, Date startDate, Date endDate)
			throws CoreException;

	/**
	 * 取得單一 coupon item
	 * 
	 * @param itemUuid
	 * @return
	 * @throws CoreException
	 */
	public CouponItem getItem(String itemUuid) throws CoreException;

	/**
	 * 取得該 member 之所有有效 coupon item
	 * 
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getItems(String memberId) throws CoreException;

	/**
	 * Map里面的key里面必须含有MODIFY_DATE,ORDER_ID,END_DATE,LOG_TYPE <br\>
	 * 取得该coupon_Code的使用纪碌，以modift_date desc排序
	 * 
	 * @param couponCode
	 * @return
	 * @throws CoreException
	 */
	public List<Map<String, Object>> getItemLogs(String couponCode) throws CoreException;

	public List<CouponItem> getAllItems(String couponUuid) throws CoreException;

	/**
	 * 取得該 member 六個月內使用過的 coupon item
	 * 
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getUsedItems(String memberId) throws CoreException;

	/**
	 * 取得該 member 可使用的 coupon 總額
	 * 
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public String getFreeItemsTotal(String memberId) throws CoreException;

	/**
	 * @param memberId
	 * @param shoppingCar
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getItems(String memberId, List<OrderProduct> products) throws CoreException;

	/**
	 * 檢驗該商品是否適用此 coupon.
	 * 
	 * @param couponItem
	 * @param product
	 * @return
	 * @throws CoreException
	 */
	public boolean isValid(CouponItem couponItem, OrderProduct product) throws CoreException;

	/**
	 * 檢驗該商品是否適用此 coupon.
	 * 
	 * @param couponItem
	 * @param product
	 * @return
	 * @throws CoreException
	 */
	public boolean isValid(CouponItem couponItem, CartOrderProduct product) throws CoreException;

	/**
	 * @param couponItem
	 * @param productId
	 * @param categoryPath
	 * @return
	 * @throws CoreException
	 */
	public boolean isValid(CouponItem couponItem, String productId, String categoryPath) throws CoreException;

	/**
	 * 為指定的 member 領用一個 coupon item, 之後可以使用 getItems 取得該 member 之所有 coupon item
	 * 
	 * @param couponUuid
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public CouponItem regCoupon(String couponUuid, String memberId) throws CoreException;

	/**
	 * @param itemUuid
	 * @param memberId
	 * @param orderId
	 * @throws CoreException
	 */
	public void useCoupon(String itemUuid, String memberId, String orderId) throws CoreException;

	/**
	 * 
	 * @param itemUuid
	 * @param memberId
	 * @param orderId
	 * @throws Exception
	 */
	public void forceUseCoupon(String itemUuid, String memberId, String orderId) throws Exception;
	
	/**
	 * 待生效coupon
	 * 
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getWaitItems(String memberId) throws CoreException;

	/**
	 * @author chin.hung
	 * @param couponItemCode
	 */
	public CouponItem getCouponItemByCode(String couponItemCode);

	/**
	 * @author chin.hung
	 */
	public CouponItem regCouponItem(CouponItem couponItem, String memberId) throws CoreException;

	/**
	 * 取得某個會員所有已取得某禮券／活動的優惠碼
	 * 
	 * @param coupon
	 * @param member
	 * @return
	 */
	public List<CouponItem> getCouponItemListByCouponAndMember(Coupon coupon, Member member);

	/**
	 * 退還已使用的禮券
	 * 
	 * @param order
	 * @param couponUuid
	 */
	public void unuseCoupon(String orderId, String couponUuid);

	/**
	 * 將禮券轉移到另一筆訂單
	 * 
	 * @param oldOrder
	 * @param newOrder
	 * @param couponUuid
	 */
	public void transferCoupon(Orders oldOrder, Orders newOrder, String couponUuid);

	/**
	 * 捞出六个月内获得礼卷
	 * 
	 * @param memberId
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getListItems(String memberId) throws CoreException;

	/**
	 * 取得coupon是否還有剩
	 * 
	 * @param couponUuid
	 * @return
	 * @throws CoreException
	 */
	public boolean getIsAvailable(String couponUuid) throws CoreException;

	/**
	 * 修改coupon起迄时间
	 * 
	 * @param couponUuid
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	public boolean updateStartEndDate(String coupon_uuid, Date startDate, Date endDate);

	/**
	 * 分页捞出couponItem
	 * 
	 * @param couponUuid
	 * @param startNode
	 * @param returnSize
	 * @return
	 * @throws CoreException
	 */
	public List<CouponItem> getListItems(String couponUuid, int startNode, int returnSize) throws CoreException;

	/**
	 * CouponItem总数
	 * 
	 * @param couponUuid
	 * @return
	 * @throws CoreException
	 */
	public int getAllItemsSize(String couponUuid) throws CoreException;

	/**
	 * 修改couponItem
	 * 
	 * @param item
	 * @return
	 * @throws CoreException
	 */
	public CouponItem updateCouponItem(CouponItem item, String memberId) throws Exception;
}
